var md5Util= require("md5.js");
//服务地址
const  requestUrl= "https://wechat.pubaogz.com"
const  appVersion ="1.0"
function jsonSort(jsonObj) {
  let arr=[];
  for(var key in jsonObj){
    arr.push(key)
  }
  arr.sort();
  let str='';
  for(var i in arr){
    str +=arr[i]+"="+jsonObj[arr[i]]+"&"
  }
  return str.substr(0,str.length-1)
}

function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()
  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function getSignValue(param){
  var md5Str = "";
  if (param == null){
    md5Str = md5Util.md5(appVersion);
   // console.log("===str===",appVersion)
  }else{
   // console.log("===str===",jsonSort(param))
    md5Str =  md5Util.md5(jsonSort(param));
  }
  //console.log("===md5===",md5Str)
  return md5Str
}
//业务变量
const sysConst= {
  //获取用户信息  获取openid 和 unionid （不一定有）
  getDeliveryClerkInfoPath:requestUrl+"/wxApp/mall/deliveryClerk/getDeliveryClerkInfoByCode",
  //订单列表
  userOrderPath:requestUrl+"/wxApp/mall/fastOrder/userOrder",
  //发货
  sendOrderPathPath:requestUrl+"/wxApp/mall/deliveryClerk/sendOrder",
  //配送列表
  getDeliveryLogPath:requestUrl+"/wxApp/mall/deliveryClerk/getDeliveryLog",
  //确认收货
  confirmOrderPath:requestUrl+"/wxApp/mall/deliveryClerk/confirmOrder",
 //配送员注册
  registerPath:requestUrl+"/wxApp/mall/deliveryClerk/register",

}
module.exports = {
  sysConst: sysConst,
  appVersion: appVersion,
  formatTime: formatTime,
  getSignValue: getSignValue
}